<?php
namespace Mob \ Model;

use Think \ Model;
use Think \ Hook;
/**请假模型
 * Class InfoModel
 */

require_once ('./Application/Mob/Common/function.php');

class JobsModel extends Model {

  public function creator($activityId='',$title,$contents,$actlongitude,$actlatitude,$startDate,$endDate,$enterpriseId,$industryId,$step)
  {
  	$data['activityId'] = empty($activityId)?getActivitySerialno():$activityId;
  	$data['jobsserialno'] = getJobsSerialno(20);
  	$data['title']=$title;
  	$data['contents']=$contents;
  	$data['actlongitude']=$actlongitude;
  	$data['actlatitude']=$actlatitude;
  	$data['startDate']=$startDate;
  	$data['industryId']=$industryId;
  	$data['endDate']=$endDate;
  	$data['enterpriseId']=$enterpriseId;
  	$data['initstep']=$step;
  	$data['currentStep']=$step;
  	$data['createUid']=get_uid();


  	if($this->add($data))
  	{
  	$this->releaseOperate($data['jobsserialno']);
  	return 	$data;
  	}

  }

  public function get_jobsDetails($jobsserialno)
  {

 /*
 $where = array('jobsserialno'=>$jobsserialno,'status'=>1);
 $jobsDetails = $this->where($where)->field('jobsserialno,title,createTime,activityId,contents,actlongitude,actlatitude,startDate,endDate,enterpriseId,step,currentStep')->find();
 return $jobsDetails;
 */
  $jobs = new \ Think \ Model();
 return $jobs->query("select j.jobsserialno,j.title,j.createTime,j.actlongitude,j.actlatitude,j.enterpriseId,j.currentStep,j.createUid,e.name as enterpriseName ,e.industry,s.stepName
from ocenter_jobs j,ocenter_enterprise e,ocenter_jobs_step s where j.jobsserialno = '$jobsserialno' and j.enterpriseId = e.Id and j.currentStep = s.stepId")[0];

  }


  public function jobsHall()
  {
  $startDate =time()-60*60;
 // $jobs = $this->where("startDate >= $startDate and status =1 and currentStep = initstep ")->field('startDate, status, currentStep, initstep,serialno,actlongitude,actlatitude,enterpriseId,industryId')->select();
// return $jobs;

   $jobs = new \ Think \ Model();
  $jobshall = $jobs->query("SELECT j.startDate,j.status,j.currentStep,j.initstep,e.name as enterpriseName,e.id as enterpriseId,j.jobsserialno,j.actlongitude,j.actlatitude,j.title,p.stepName,FROM_UNIXTIME(j.startDate,'%Y-%m-%d %H:%i') as StartTime FROM ocenter_jobs
    j,ocenter_enterprise e,ocenter_jobs_step p  WHERE  j.startDate >= $startDate and j.status  in (1,2) and j.currentStep = j.initstep and j.enterpriseId = e.Id  and j.currentStep = p.stepId order by StartTime ");
  return $jobshall;
  }

  public function releaseOperate($jobsserialno)
  {
   $this->where("jobsserialno = '$jobsserialno'")->save(array('status'=>1));



  }

  public function interviewHall($uid,$day)
  {
  $jobs = new \ Think \ Model();
  $day = empty($day)?strtotime(date('Y-m-d',time()))-86400*90:strtotime($day);
  $interviewHall = $jobs->query("select j.jobsserialno,j.currentStep,j.signTime,j.contents,j.signserialno,j.enterpriseId,j.industry,j.signUid,j.signLongitude,j.signLatitude,e.name as enterpriseName,p.stepName from ocenter_jobs_step_signrecored
  j,ocenter_enterprise e,ocenter_jobs_step  p   where j.jobsserialno in (   SELECT jobsserialno FROM ocenter_jobs_step_signrecored  WHERE signTime >= $day AND signUid = $uid AND currentStep = 1
   and signStatus =1) and j.currentStep in (2,3) and signStatus = 1   and j.enterpriseId = e.Id and j.currentStep = p.stepId");
  return $interviewHall;

  }






















}